package com.recsmile.rpc;

import com.recsmile.rpc.provider.MessageSendExecutor;
import org.apache.commons.lang3.time.StopWatch;

import java.util.concurrent.CountDownLatch;

/**
 * Hello world!
 *
 */
public class Provider
{
    public static void main( String[] args )
    {
        try{
            MessageSendExecutor executor = new MessageSendExecutor("127.0.0.1:8899");
            int parallel = 10000;
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();
            CountDownLatch signal = new CountDownLatch(1);
            CountDownLatch finish = new CountDownLatch(parallel);
            for (int i = 0; i < parallel; i++){
                new Thread(new CalcParallelRequestThread(signal,finish,executor, i)).start();
            }

            signal.countDown();
            finish.await();
            stopWatch.stop();
            System.out.println(String.format("RPC调用总共耗时: [%s] 毫秒", stopWatch.getTime()));

            executor.stop();
        }catch (Exception e){
            e.printStackTrace();
        }
        //System.out.println( "Hello World!" );

    }
}
